| Conditions | 5 |
| Paths | 5 |
| Total Lines | 25 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | const fs = require('fs') |
||
| 5 | module.exports = (output, data) => { |
||
| 6 | if (!data) { |
||
| 7 | return null |
||
| 8 | } |
||
| 9 | if (!output) { |
||
| 10 | console.log(data) |
||
| 11 | } else if (typeof output === 'string') { |
||
| 12 | const path = join(__dirname, '../', output) |
||
| 13 | fs.open(path, fs.W_OK, err => { |
||
| 14 | if (err) { |
||
| 15 | console.error(`Cannot write file to ${path}`) |
||
| 16 | return |
||
| 17 | } |
||
| 18 | // TODO: maybe use appendFile for readStream |
||
| 19 | fs.writeFileSync(path, data) |
||
| 20 | }) |
||
| 21 | } else if (output instanceof Writable) { |
||
| 22 | output.write(data + '\r\n') |
||
| 23 | output.on('error', err => { |
||
| 24 | console.error(err) |
||
| 25 | }) |
||
| 26 | } else { |
||
| 27 | console.error('Invalid Output') |
||
| 28 | } |
||
| 29 | } |
||
| 30 |